package com.cris.domain;

import com.cris.model.Product;
import com.cris.service.ProductService;

import java.util.*;

public class ProductCatalog {

	private List<ItemId> idList = new ArrayList<>();
	private ProductService productService;

	private Map<ItemId, ProductDescription > descriptions = new HashMap<ItemId, ProductDescription>();
	public ProductCatalog(){
		productService = new ProductService();
		List<Product> productList= productService.getProductList();

		for(Product product:productList){
			ItemId id = new ItemId(product.getId());
			Money price = new Money(product.getPrice());
			ProductDescription desc = new ProductDescription(id,price,product.getName());
			descriptions.put(id,desc);
			idList.add(id);
		}

	}
	public ProductDescription getProductDescription(ItemId id) {
		return descriptions.get(id);
	}
	public Map<ItemId, ProductDescription> getDescriptions() {
		return descriptions;
	}
	public ItemId getItemId(long id) {
		for (ItemId itemId:idList){
			if(id==itemId.getId())
				return itemId;
		}
		return null;
	}	
}
